package com.project.hqshorttaxi.service.impl;

import com.project.hqshorttaxi.dto.BlackListParam;
import com.project.hqshorttaxi.dto.CameraParam;
import com.project.hqshorttaxi.entity.BlackList;
import com.project.hqshorttaxi.entity.Camera;
import com.project.hqshorttaxi.mapper.BlackListMapper;
import com.project.hqshorttaxi.mapper.CameraMapper;
import com.project.hqshorttaxi.service.BlackListService;
import com.project.hqshorttaxi.service.CameraService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;

@Service
public class BlackListServiceImpl implements BlackListService {

    @Resource
    private BlackListMapper blackListMapper;

    @Override
    public BlackList getById(Integer id) {
        return blackListMapper.selectByPrimaryKey(id);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void insert(BlackList entity) throws Exception {
        blackListMapper.insertSelective(entity);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void update(BlackList entity) throws Exception {
        blackListMapper.updateByPrimaryKeySelective(entity);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void delete(Integer id) throws Exception {
        blackListMapper.deleteByPrimaryKey(id);
    }

    @Override
    public List<BlackList> list(BlackListParam param) {
        Example example = new Example(BlackList.class);
        Example.Criteria c = example.createCriteria();
        if (!StringUtils.isEmpty(param.getPlateNumber())) {
            c.andLike("plateNumber", "%" + param.getPlateNumber() + "%");
        }
        example.orderBy("createTime").desc();
        List<BlackList> list = blackListMapper.selectByExample(example);
        return list;
    }
}
